package cn.itcast.generate;

import cn.itcast.generate.log.GenerateLog;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class LogDataSourceApp {

    public static void main(String[] args) throws IOException, InterruptedException, ParseException {
        SpringApplication.run(LogDataSourceApp.class,args);
        System.out.println("启动日志收集服务");
        //运行jar文件时，通过参数指定日志数据的输出目录
        String path = args[0];//主要作用获取在linux里命令的路径参数，用户在获取到的路径下保存日志信息
//        String path = "D:\\dev\\nginx.log";
        File file = new File(path);
        //无限循环生成日志保存到指定log文件下
        while (true) {
            FileOutputStream fos = new FileOutputStream(file, true);
            String content = GenerateLog.generateLog() + "\n";
            fos.write(content.getBytes());
            //间隔1秒钟生成1条日志数据
            System.out.println(content);
            TimeUnit.SECONDS.sleep(1);
            fos.close();
        }

    }

}
